<template>
    <div class='reminder'>
        <div class="container">
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="search-con">
                
                <el-form-item label="输入搜索：" prop="key" style="margin-right:25px;">
                    <el-input v-model="queryParams.key" placeholder="商品名称/货号" clearable size="small" />
                </el-form-item>
                <el-form-item label="提醒状态" prop="key_order_type" style="margin-right:25px;">
                    <el-select v-model="queryParams.key_order_type" placeholder="请选择" clearable size="small">
                        <el-option v-for="dict in statusList" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="收货人：" prop="key" style="margin-right:25px;">
                    <el-input v-model="queryParams.key" placeholder="收货人姓名/手机号码" clearable size="small" />
                </el-form-item> -->
                <el-form-item label="设置时间：" prop="key_range" style="margin-right:25px;">
                    <el-date-picker v-model="queryParams.key_range" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
                        value-format="yyyy-MM-dd" placeholder="请选择提交时间范围" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="22">
                    <!-- <el-button type="primary" icon="el-icon-plus" size="mini" @click="title='新增';handleShow='add'" v-hasPermi="['user:depart:add']">
                        新增</el-button> -->
                        <el-col :span="22">
                    <el-button type="primary" icon="el-icon-edit" size="mini"
                        @click="handleBulk" v-hasPermi="['customer:manage:add']">
                        批量修改</el-button>
                </el-col>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight :height="tableList.length>0?'900px':'120px'" @selection-change="handleSelectionChange"
                @row-click="toggleSelection">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="订单编号" align="center" prop="id" />
                <el-table-column label="用户名" align="center" prop="time" />
                <el-table-column label="手机号码" align="center" prop="account" />
                <el-table-column label="邮箱地址" align="center" prop="amount" />
                <el-table-column label="商品名称" align="center" prop="pay_way" />
                <el-table-column label="商品货号" align="center" prop="source" />
                <el-table-column label="设置时间" align="center" prop="source" />
                <el-table-column label="提醒状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <span>
                            {{selectDictLabel(statusList, scope.row.status)}}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="title='编辑';form=JSON.parse(JSON.stringify(scope.row));handleShow='edit'" v-hasPermi="['user:depart:edit']">
                            查看订单
                        </el-button>
                        <el-button v-if="scope.row.status==0" size="mini" type="text" @click="handleAble(scope.row)" v-hasPermi="['user:depart:stop']">订单跟踪
                        </el-button>
                        <el-button v-if="scope.row.status==1" size="mini" type="text" @click="handleAble(scope.row)" v-hasPermi="['user:depart:start']">启用
                        </el-button> -->
                        <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['user:depart:del']">
                            删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="pageCount>0" :pageCount="pageCount" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
        </div>
        <el-dialog :title="title" visible v-if="handleShow" @close="close()" width="400px" append-to-body :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="80px" v-loading="formLoading">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="部门名称" prop="name">
                            <el-input v-model="form.name" placeholder="请输入部门名称" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="close()">取 消</el-button>
                <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { getSectorLists, setSector, setSectorStatus, delSector } from "@/api/user/department.js"

import { departStatus } from "@/api/dictionary"

import throttle from 'lodash.throttle'
export default {
    name: 'reminder',
    props: {

    },
    data() {
        return {
            showSearch: true,
            loading: false,
            pageCount: 0,
            total: 0,
            queryParams: {
                page: 1,
                limit: 20,
                key: null,
            },
            tableList: [],
            statusList: departStatus,
            handleShow: "",
            formLoading: false,
            form: {
                id: null,
                name: null,
            },
            rules: {
                name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
            },
            title: "",
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            // this.loading = true;
            // getSectorLists(this.queryParams).then(res => {
            //     this.tableList = res.data.lists;
            //     this.pageCount = res.data.pageCount;
            //     this.loading = false;
            // });
        },
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        close() {
            this.form = {}
            this.handleShow = ""
        },
        toggleSelection(row) {
            this.$refs.tableList.toggleRowSelection(row);
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectData = selection;
        },
        handleBulk(ids) {
            this.$confirm('是否确认批量修改?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("修改成功");
            })
        },
        handleAble(row) {
            let label = row.status == 0 ? '停用' : '启用';
            this.$confirm(`是否将“${row.name}”${label}?`, "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return setSectorStatus({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess(`${label}成功`);
            })
        },
        handleDelete(row) {
            this.$confirm('是否确认删除' + '"' + row.name + '"' + '?', "警告", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(function () {
                return delSector({ id: row.id });
            }).then(() => {
                this.getList();
                this.msgSuccess("删除成功");
            })
        },

        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.formLoading = true;
                    setSector(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        this.close()
                        this.formLoading = false;
                        this.getList();
                    }).catch(() => {
                        this.formLoading = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
</style>
